<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
    <el-form-item label-width="60px;" label="Name" prop="name">
      <el-input
        v-model="queryParams.name"
        placeholder=""
        clearable
        @keyup.enter.native="handleQuery"
        style="width: 150px;"
      />
    </el-form-item>
    <el-form-item label-width="80px;" label="Phone" prop="phone1">
      <el-input
        v-model="queryParams.phone1"
        placeholder=""
        clearable
        @keyup.enter.native="handleQuery"
        style="width: 150px;"
      />
    </el-form-item>
    <el-form-item label="Email" prop="email1">
      <el-input
        v-model="queryParams.email1"
        placeholder=""
        clearable
        @keyup.enter.native="handleQuery"
        style="width: 150px;"
      />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">Search</el-button>
      <el-button v-if="false" icon="el-icon-refresh" size="mini" @click="resetQuery">Reset</el-button>
    </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >Add</el-button>
      </el-col>
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="success"-->
      <!--plain-->
      <!--icon="el-icon-edit"-->
      <!--size="mini"-->
      <!--:disabled="single"-->
      <!--@click="handleUpdate"-->
      <!--v-hasPermi="['system:candidate:edit']"-->
      <!--&gt;修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="danger"-->
      <!--plain-->
      <!--icon="el-icon-delete"-->
      <!--size="mini"-->
      <!--:disabled="multiple"-->
      <!--@click="handleDelete"-->
      <!--v-hasPermi="['system:candidate:remove']"-->
      <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
      <!--<el-button-->
      <!--type="warning"-->
      <!--plain-->
      <!--icon="el-icon-download"-->
      <!--size="mini"-->
      <!--@click="handleExport"-->
      <!--v-hasPermi="['system:candidate:export']"-->
      <!--&gt;导出</el-button>-->
      <!--</el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="candidateList"
      border
      @selection-change="handleSelectionChange">
      <el-table-column
        min-width="60px"
        label="Action"
        align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >Edit</el-button>
          <br>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-hasPermi="['system:candidate:del']"
            @click="handleDelete(scope.row)"
          >Del</el-button>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" label="Name" align="left" prop="name" />
      <el-table-column :show-overflow-tooltip="true" label="Company1" align="left" prop="ccompanyList[0].com" />
      <el-table-column :show-overflow-tooltip="true" label="Company2" align="left" prop="ccompanyList[1].com" />
      <el-table-column :show-overflow-tooltip="true" label="Company3" align="left" prop="ccompanyList[2].com" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { listCandidate, getCandidate, delCandidate, addCandidate, updateCandidate } from "@/api/system/candidate";
  import { getToken } from "@/utils/auth";

  export default {
    name: "CandidateEntry",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        cid: 0,
        // 【请填写功能名称】表格数据
        candidateList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        openJobs: false,
        queryParamsJob:{
          cid: null
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          email1: null,
          email2: null,
          name: null,
          phone1: null,
          phone2: null,
          gender: null,
          salary: null,
          education: null,
          other: null,
          district: null,
          age: null,
          jobFunction: null,
          birthyear: null
        },
        // 表单参数
        form: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listCandidate(this.queryParams).then(response => {
          this.candidateList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        const obj = { path: "/system/candidate/candidateAdd", name: "CandidateAdd" };
        this.$tab.closePage(obj);
        setTimeout(()=> {
          this.$router.push({path:'/system/candidate/candidateAdd', query: {type: 1}})
        }, 300);
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        // 关闭指定页签
        const id = row.id || this.ids
        const obj = { path: "/system/candidate/candidateAdd", name: "CandidateAdd" };
        this.$tab.closePage(obj);
        setTimeout(()=> {
          this.$router.push({path:'/system/candidate/candidateAdd',query: {id:id, type: 1}})
        }, 300);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('Delete？').then(function() {
          return delCandidate(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("success");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/candidate/export', {
          ...this.queryParams
        }, `candidate_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>

<style rel="stylesheet/scss" lang="scss">
</style>
